﻿using LitJson;
using System;
using System.Diagnostics;
using TableCore.Plugin;

namespace Teset
{
    internal class Program
    {
        static double Pow(double baseValue, int pow)
        {
            double v = 1;
            for (int i = 0; i < pow; i++)
            {
                v *= baseValue;
            }
            return v;
        }

        static void Main(string[] args)
        {
            //            Regex mCmdRegex = new Regex(@"(?<=#alias#) .+", RegexOptions.IgnoreCase);
            //            var matchs = mCmdRegex.Matches(@"#alias# line1 line1
            //#alias# line2 line2");
            //            foreach(Match m in matchs)
            //            {
            //                Console.WriteLine(m.Value);
            //            }

            var formula = new FormulaFormatter().Factory;
            try
            {
                //                formula.CompileFormula(@"
                //#alias# c=Combine t=Time w=Weather a=ActorState task=ActorTask
                //#alias# b=Building s=Statistics f=Festival ani=Animal k=Knowledge
                //#alias# p=ActorProperty ct=Counter", "");
                //var content = formula.Format(" a_12 &  b_12 | c_1  & !ani_23", "");
                formula.ParseCmd(@"
#value# ActorState=1 Combine=2
#alias# AS=ActorState B=Building C=Combine");
                formula.GetReadyForCompilingFormula();
                var content = formula.CompileFormula("NPC:11 in COM:12");
                Console.WriteLine(content);

                Console.WriteLine(string.Format("Type ID: {0}", formula.GetType().GetHashCode()));
            }
            catch (System.Exception e)
            {
                Console.WriteLine(e);
            }

            //Console.Write("Input Facotr: ");
            //var factor = Console.ReadLine();
            //Console.Write("Input Base: ");
            //var baseValue = Console.ReadLine();

            double p, price;
            //if(double.TryParse(factor, out p) && double.TryParse(baseValue, out price))
            {
                p = 4.918;
                price = 120000;
                var mp = p * 0.01d / 12d;
                double sum = 0;
                var peryear = price / 5d;
                var permonth = price / 60d;
                var power = Pow(1 + mp, 60);
                for (int i = 1; i <= 60; i++)
                {
                    var f = price * mp * power / (power - 1);
                    sum += f;
                    Console.WriteLine($"Month {i}: {f}");
                    if (i % 12 == 0)
                    {
                        Console.WriteLine($"Year: {sum} (Percent: {(sum - peryear) * 100 / peryear})");
                        sum = 0;
                    }
                }
            }
            //else
            //{
            //    Console.WriteLine("Invalid input values");
            //}

            //var file = new SitcomFile();
            //file.Load("hello, a&&b | !c ab \"&& || :\"\nlsfsdlfs");
            //file.BeginRead();
            //while (file.StartLine())
            //{
            //    while (file.NextKeyword())
            //    {
            //        Console.WriteLine(string.Format("{0}: {1}", file.keyword.type, file.keyword.text));
            //    }
            //}
            Console.ReadKey();
        }
    }
}
